import React,{Component} from 'react'
import {connect} from 'react-redux'
import {getDetailById} from '../../store/actionCreator'
var showdown  = require('showdown')
class Detail extends Component{
    constructor(){
        super();
        this.state={

        }
    }
    componentDidMount(){
        //路由参数
        //console.log(this.props.match.params.id)
        this.props.getDetailById(this.props.match.params.id)
    }
    render(){
        var content = this.props.content.content
        //console.log(content)
        return(
            <React.Fragment>
                <div dangerouslySetInnerHTML={{__html:new showdown.Converter().makeHtml(content)}}></div>
            </React.Fragment>
        )
    }
}
const mapStateToProps = (state)=>{
    return{
        content:state.get('detail').get('content').toJS()
    }
  }
  
  const mapDispatchToProps = (dispatch)=>{
    return{
        getDetailById(data){
            var action = getDetailById(data);
            dispatch(action);
        }
    }
  }
  export default connect(mapStateToProps,mapDispatchToProps)(Detail);